package seqlist.stack_queue.leetcode;

import java.util.Stack;

/**
 * @author yuisama
 * @date 2023/03/21 21:19
 **/
public class MinStack {
    private Stack<Integer> s1;
    private Stack<Integer> s2;
    public MinStack() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    public void push(int val) {
        s1.push(val);
        if(s2.isEmpty()) {
            s2.push(val);
        }else {
            int tempMin = s2.peek();
            if(val < tempMin) {
                s2.push(val);
            }else {
                s2.push(tempMin);
            }
        }
    }

    public void pop() {
        s1.pop();
        s2.pop();
    }

    public int top() {
        return s1.peek();
    }

    public int getMin() {
        return s2.peek();
    }
}